package com.atldy.commerce.controller;

import com.atldy.commerce.commence.TableId;
import com.atldy.commerce.commence.goods.DeductGoodsInventory;
import com.atldy.commerce.commence.goods.GoodsInfo;
import com.atldy.commerce.commence.goods.SimpleGoodsInfo;
import com.atldy.commerce.service.GoodsService;
import com.atldy.commerce.vo.PageSimpleGoodsInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @version 1.0
 * @Author: li-dong-yang
 * @CreateTime: 2021-08-21 21:44
 * @Description： 商品服务接口
 */
@Api(value = "商品服务接口", description = "商品服务接口")
@RequestMapping("/goods")
@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "查询商品详细信息", notes = "查询商品详细信息")
    @PostMapping("/getGoodsInfos")
    public List<GoodsInfo> getGoodsInfos(@RequestBody TableId tableId) {
        return goodsService.getGoodsInfos(tableId);
    }

    @ApiOperation(value = "获取分页商品信息", notes = "获取分页商品信息")
    @GetMapping("/getPageSimpleGoodsInfos")
    public PageSimpleGoodsInfo getPageSimpleGoodsInfos(int page) {
        return goodsService.getPageSimpleGoodsInfos(page);
    }

    @ApiOperation(value = "根据tableId查询商品简单信息", notes = "根据tableId查询商品简单信息")
    @PostMapping("/getSimpleGoodsInfos")
    public List<SimpleGoodsInfo> getSimpleGoodsInfos(@RequestBody TableId tableId) {
        return goodsService.getSimpleGoodsInfos(tableId);
    }

    @ApiOperation(value = "扣减库存", notes = "扣减库存")
    @PostMapping("/deductGoodsInventory")
    public Boolean deductGoodsInventory(@RequestBody List<DeductGoodsInventory> deductGoodsInventory) {
        return goodsService.deductGoodsInventory(deductGoodsInventory);
    }

}